using System;
using System.ComponentModel;

namespace Clifton.Tools.Data
{
	public class BindableDataElement : INotifyPropertyChanged
	{
		public event PropertyChangedEventHandler PropertyChanged;
		public event EventHandler TextChanged;
		protected string text;

		public string Text
		{
			get { return text; }
			set
			{
				if (text != value)
				{
					text = value;
					OnTextChanged();
				}
			}
		}

		public BindableDataElement()
		{
		}

		protected virtual void OnTextChanged()
		{
			if (TextChanged != null)
			{
				TextChanged(this, EventArgs.Empty);
			}

			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs("Text"));
			}
		}
	}
}
